package yk.controller;

import com.yk.pojo.CommonResult;
import com.yk.pojo.Payment;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import yk.dao.PayMentMapper;

import java.util.List;

@RestController
public class PaymentController {
    private static final Logger logger = LoggerFactory.getLogger(PaymentController.class);


    @Autowired
    PayMentMapper payMentMapper;

    @Value("${server.port}")
    private String serverPort;

    @RequestMapping("/payment/all")
    @ResponseBody
    public CommonResult<List<Payment>> all() {
        return new CommonResult<List<Payment>>(200, "查询成功"+serverPort, payMentMapper.queryAll());
    }

    @RequestMapping("/payment/get/{id}")
    @ResponseBody
    public CommonResult<Payment> getById(@PathVariable Long id) {
        return new CommonResult<Payment>(200, "查询成功"+serverPort, payMentMapper.queryById(id));
    }

    @PostMapping("/payment/create")
    @ResponseBody
    public CommonResult<Integer> create(@RequestBody  Payment payment) {
        return new CommonResult<Integer>(200, "插入数据库成功" + serverPort, payMentMapper.insert(payment));
    }

    @GetMapping("/payment/lb")
    @ResponseBody
    public Object lb() {
        return serverPort;
    }

    @SneakyThrows
    @GetMapping("/payment/delay")
    @ResponseBody
    public Object delay() {
        Thread.sleep(3000);
        return new CommonResult<String>(200, serverPort, serverPort);
    }
}
